﻿using System;
using System.Text;

namespace Environment_Updater {
    class Plane {
        private String name;
        private float mass; // kg

        private WorldVector position; // m
        private WorldVector velocity; // m/s
        private WorldVector acceleration; // m/s^2
        private WorldVector force; // N (kg * m/s^2)

        private DateTime lastUpdate;

        public Plane(String name, int x, int y, int z) {
            this.name = name;
            this.mass = 335000; // minimum weight of Boeing 747

            this.position = new WorldVector(x, y, z);
            this.acceleration = new WorldVector();
            this.force = new WorldVector();

            this.lastUpdate = DateTime.Now;
        }

        public void SetTakingOff() {
            // adjust force accordingly
            this.force.Z = 100000;
        }

        public void SetLanding() {
            // adjust force accordingly
            this.force.Z = -100000;
        }

        public void Update() {
            DateTime thisUpdate = DateTime.Now;
            float t = (float) ((thisUpdate - lastUpdate).TotalMilliseconds / 1000);
            lastUpdate = thisUpdate;

            // a = f / m
            this.acceleration = this.force.times(1 / this.mass);

            // v = at
            this.velocity = this.velocity.plus(this.acceleration.times(t));

            // x = vt + 1/2 * at^2
            this.position = this.position.plus(this.velocity.times(t).plus(this.acceleration.times(t * t / 2)));

            Console.WriteLine("[" + DateTime.Now.ToString("hh:mmtt") + "] " + this.name + " {\n\t Pos: " + this.position + " m\n\t Vel: " + this.velocity + " m/s\n\t Acc: " + this.acceleration + " m/s^2\n\t For: " + this.force + " N\n}\n");
        }

        public WorldVector Velocity {
            set { this.velocity = value; }
        }

        public WorldVector Acceleration {
            set { this.acceleration = value; }
        }
    }
}
